package com.example.evanproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.evanproject.domain.Type;
import com.example.evanproject.service.TypeService;
import com.example.evanproject.mapper.TypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author hanxiaoqi
* @description 针对表【type】的数据库操作Service实现
* @createDate 2024-03-09 21:52:13
*/
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type>
    implements TypeService{

    @Autowired
    private TypeMapper typeMapper;
    public List<Type> selectall(Integer fid){
        return typeMapper.selectall(fid);
    }

    //      包含含有新闻列表数据
    public   List<HashMap> selecthasnews(){
//        如果定义hash的时候 你一个新的都是重新声明 要不掩会影响以前的
        List<Type> list=typeMapper.slectnewtype();
        List<HashMap> typelist=new ArrayList<>();
        for (Integer i=0;i<list.size();i++){
            HashMap<String, Object> params = new HashMap<>();
            params.put("typeName",list.get(i).getTypeName());
            List<HashMap> newlistmap=new ArrayList<>();
            for (Integer j=0;j<list.get(i).getNewlist().size();j++){
                HashMap<String,Object> newlist=new HashMap<>();
                if(list.get(i).getNewlist().get(j).getTypeId()==list.get(i).getTypeId()){
                    newlist.put("id",list.get(i).getNewlist().get(j).getIId());
                    newlist.put("title",list.get(i).getNewlist().get(j).getITitle());
                    newlistmap.add(newlist);
                }
            }
            params.put("newlist", newlistmap);
            typelist.add(params);
        }

        return typelist;
    }

}




